package system.company.base.Objects;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import system.company.actor.Ordinary_Staff.BaseHibernateDAO;

/**
 	* A data access object (DAO) providing persistence and search support for Object_SalaryRecord entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see system.company.base.Objects.Object_SalaryRecord
  * @author MyEclipse Persistence Tools 
 */

public class Object_SalaryRecordDAO extends BaseHibernateDAO  {
    private static final Log log = LogFactory.getLog(Object_SalaryRecordDAO.class);
	//property constants
	public static final String _ID = "ID";
	public static final String NAME = "name";
	public static final String DATE = "date";
	public static final String SALARY = "salary";
	public static final String DEDUCE = "deduce";
	public static final String BONUS = "bonus";
	public static final String TOTAL = "total";
	public static final String PAIDORNOT = "paidornot";
	public static final String DEPARTMENT = "department";



    
    public void save(Object_SalaryRecord transientInstance) {
        log.debug("saving Object_SalaryRecord instance");
        try {
        	Transaction tran = getSession().getTransaction();
			tran.begin();
            getSession().save(transientInstance);

            tran.commit();
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Object_SalaryRecord persistentInstance) {
        log.debug("deleting Object_SalaryRecord instance");
        try {
        	Transaction tran = getSession().getTransaction();
			tran.begin();
            getSession().delete(persistentInstance);
            tran.commit();
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Object_SalaryRecord findById( java.lang.Integer id) {
        log.debug("getting Object_SalaryRecord instance with id: " + id);
        try {
            Object_SalaryRecord instance = (Object_SalaryRecord) getSession()
                    .get("system.company.base.Objects.Object_SalaryRecord", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Object_SalaryRecord instance) {
        log.debug("finding Object_SalaryRecord instance by example");
        try {
            List results = getSession()
                    .createCriteria("system.company.base.Objects.Object_SalaryRecord")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Object_SalaryRecord instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Object_SalaryRecord as model where model." 
         						+ propertyName + "=?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}
    public List findByTwoProperty(String propertyName_1,String propertyName_2, Object value_1, Object value_2) {
		log.debug("finding Object_SalaryRecord instance with property: "
				+ propertyName_1 + ", value: " + value_1+"  "+ propertyName_2 + ", value: " + value_2);
		try {
			String queryString = "from Object_SalaryRecord as model where model."
					+ propertyName_1 + "= ?"+" and model."+propertyName_2+"=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value_1);
			queryObject.setParameter(1, value_2);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
    public List findByIDAndDepartment(Object ID,Object Department
	) {
		return findByTwoProperty(_ID,DEPARTMENT,ID,Department
		);
	}
	public List findByID(Object ID
	) {
		return findByProperty(_ID, ID
		);
	}
	
	public List findByName(Object name
	) {
		return findByProperty(NAME, name
		);
	}
	
	public List findByDate(Object date
	) {
		return findByProperty(DATE, date
		);
	}
	
	public List findBySalary(Object salary
	) {
		return findByProperty(SALARY, salary
		);
	}
	
	public List findByDeduce(Object deduce
	) {
		return findByProperty(DEDUCE, deduce
		);
	}
	
	public List findByBonus(Object bonus
	) {
		return findByProperty(BONUS, bonus
		);
	}
	
	public List findByTotal(Object total
	) {
		return findByProperty(TOTAL, total
		);
	}
	
	public List findByPaidornot(Object paidornot
	) {
		return findByProperty(PAIDORNOT, paidornot
		);
	}
	
	public List findByDepartment(Object department
	) {
		return findByProperty(DEPARTMENT, department
		);
	}
	

	public List findAll() {
		log.debug("finding all Object_SalaryRecord instances");
		try {
			String queryString = "from Object_SalaryRecord";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Object_SalaryRecord merge(Object_SalaryRecord detachedInstance) {
        log.debug("merging Object_SalaryRecord instance");
        try {
            Object_SalaryRecord result = (Object_SalaryRecord) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Object_SalaryRecord instance) {
        log.debug("attaching dirty Object_SalaryRecord instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Object_SalaryRecord instance) {
        log.debug("attaching clean Object_SalaryRecord instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}